package com.gome.oa.custom.editor;

import java.awt.Component;
import java.util.Date;

import javax.swing.AbstractCellEditor;
import javax.swing.JSpinner;
import javax.swing.JTable;
import javax.swing.SpinnerDateModel;
import javax.swing.table.TableCellEditor;

/**
 *
 * @author: tang li
 * @date: 2016年8月20日
 * @desc:
 *
 */
public class DatetimeTableCellEditor extends AbstractCellEditor implements TableCellEditor {

	private static final long serialVersionUID = -6573800225088575750L;
	private JSpinner timeSpinner;
	
	public DatetimeTableCellEditor() {
		super();
	}

	public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row,
			final int column) {
		
		if(value == null)
			return null;
		
		timeSpinner = new JSpinner(new SpinnerDateModel());
		JSpinner.DateEditor timeEditor = new JSpinner.DateEditor(timeSpinner, "yyyy-MM-dd HH:mm");
		timeSpinner.setEditor(timeEditor);
		timeSpinner.setValue((Date)value);

		return timeSpinner;
	}

	public Object getCellEditorValue() {
		if(timeSpinner == null)
			return null;
		return timeSpinner.getValue();
	}

}
